package com.example.cybz.acl.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.cybz.acl.mapper.AdminMapper;
import com.example.cybz.acl.service.AdminService;
import com.example.cybz.model.acl.Admin;
import com.example.cybz.vo.acl.AdminQueryVo;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Log4j2
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Override
    public Page<Admin> selectAdimnPage(AdminQueryVo adminQueryVo, Page<Admin> adminPage) {
        log.info("查询用户信息");
        // 构建查询信息
        LambdaQueryChainWrapper<Admin> adminLambdaQueryChainWrapper = new LambdaQueryChainWrapper<>(baseMapper);
        // 判断昵称是否为空
        if (!StringUtils.isEmpty(adminQueryVo.getName())){
            adminLambdaQueryChainWrapper.like(Admin::getName, adminQueryVo.getName());
        }
        // 判断用户名是否为空
        if(!StringUtils.isEmpty(adminQueryVo.getUsername())){
            adminLambdaQueryChainWrapper.like(Admin::getUsername, adminQueryVo.getUsername());
        }

        // 获取查询结果
        Page<Admin> adminModel = adminLambdaQueryChainWrapper.page(adminPage);
        // 返回
        return adminModel;
    }
}
